/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fx.menu;

import fx.Home;
import fx.beer.BeerChooseController;
import fx.beer.BeerController;
import fx.judge.JudgeController;
import fx.reports.beerCharacteristics.BeerCharacteristicsController;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Popup;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 * FXML Controller class
 *
 * @author Jandrei
 */
public class MenuController extends AnchorPane implements Initializable {

    private Stage stage;
    private Home application;
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private MenuItem btnBeer;

    @FXML
    private MenuItem btnJudge;

    @FXML
    private Label lbMessage;
    
    
     @FXML
    void openBeerCharacteristics(ActionEvent event) {
        try {
            BeerCharacteristicsController characteristics = (BeerCharacteristicsController) application.replaceSceneContent("reports/beerCharacteristics/beerCharacteristics.fxml", Home.LEVELKNOWLEDGEWIDTH, Home.LEVELKNOWLEDGEHEIGTH, "Report by Feature Beer");
            characteristics.setApp(application);
        } catch (Exception ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    @FXML
    private Button btnLogout;

    @FXML
    private Button btnExit;

    @FXML
    void exit(ActionEvent event) {
        Platform.exit();
    }

    @FXML
    void logout(ActionEvent event) {
        application.gotoLogin();
    }

    @FXML
    void openJudge(ActionEvent event) {
        try {
            JudgeController judge = (JudgeController) application.replaceSceneContent("judge/Judge.fxml", Home.JUDGEWIDTH, Home.JUDGEHEIGTH, "Entry judge");
            judge.setApp(application);
        } catch (Exception ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @FXML
    void openBeer(ActionEvent event) {
        try {
            BeerController beer = (BeerController) application.replaceSceneContent("beer/Beer.fxml", Home.BEERWIDTH, Home.BEERHEIGTH, "Entry beer");
            beer.setApp(application);
        } catch (Exception ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @FXML
    void openAvaliation(ActionEvent event) {
        try {
            BeerChooseController choose = (BeerChooseController) application.replaceSceneContent("beer/beerChoose.fxml", Home.BEERCHOOSERWIDTH, Home.BEERCHOOSERHEIGTH, "Select beer");
            choose.setApp(application);
        } catch (Exception ex) {
            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
        }
//        try {
//            AvaliationController avaliation = (AvaliationController) application.replaceSceneContent("avaliation/Avaliation.fxml");
//            avaliation.setApp(application);
//        } catch (Exception ex) {
//            Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }

    @FXML
    void initialize() {
        assert btnBeer != null : "fx:id=\"btnBeer\" was not injected: check your FXML file 'menu.fxml'.";
        assert btnJudge != null : "fx:id=\"btnJudge\" was not injected: check your FXML file 'menu.fxml'.";
        assert lbMessage != null : "fx:id=\"lbMessage\" was not injected: check your FXML file 'menu.fxml'.";

    }

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }

    public void setApp(Home application) {
        this.application = application;
//        User loggedUser = application.getLoggedUser();
//        user.setText(loggedUser.getId());
//        email.setText(loggedUser.getEmail());
//        phone.setText(loggedUser.getPhone());
//        if (loggedUser.getAddress() != null) {
//            address.setText(loggedUser.getAddress());
//        }
//        subscribed.setSelected(loggedUser.isSubscribed());
//        success.setOpacity(0);
//        Judge loggedUser = application.getLoggedUser();
//        user.setText(loggedUser.getId());
//        email.setText(loggedUser.getEmail());
//        phone.setText(loggedUser.getPhone());
//        if (loggedUser.getAddress() != null) {
//            address.setText(loggedUser.getAddress());
//        }
//        subscribed.setSelected(loggedUser.isSubscribed());
//        success.setOpacity(0);
    }

    public void setMessage(String type, String text) {
//        if (type.equals("error")) {
//            lbMessage.setStyle("color");
//        } else if (type.equals("success")) {
//        } else {
//
//        }
        lbMessage.setText(text);
    }

}
